import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;


public class CallerThread extends Thread{

	static final int portNum = 7005;
	
	CallerThread(InetAddress reachable) throws IOException{
		Socket socket = null;
        PrintWriter out = null;
        BufferedReader in = null;

        try {
            socket = new Socket(reachable, portNum);
            out = new PrintWriter(socket.getOutputStream(), true);
            in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            
            BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
            String fromServer;

            System.out.println("Calling Reachable: "+reachable.getHostAddress());
            out.println("Calling Reachable");
            fromServer = in.readLine();
            System.out.println("Caller received: " + fromServer);
            

            out.close();
            in.close();
            stdIn.close();
            socket.close();
        } catch (UnknownHostException e) {
            System.err.println("Unknown Host");
        } catch (IOException e) {
            System.err.println("Couldn't get I/O for the connection to host");
        }


	}
}
